<template>
	<view class="box">
	<!-- 头部导航 -->
  <uni-nav-bar left-icon="left"    :statusBar="true" titleSize="30px" leftText="返回" right-text="提交" @clickRight="btnok"  title="修改调拨"  @clickLeft="back"   :fixed="true" backgroundColor="#3286ed" color="#fff"/>
	<u-cell>
	    <template #title>
	        <view class="u-cell-text" style="color: #ccc;">调拨单</view>
	    </template>
		</u-cell>
		<u--form class="form" labelPosition="left" labelWidth="100px" :model="form" ref="form">
			<u-form-item  label="库存调拨单号" prop="serialNum" borderBottom ref="item1"  >
				<u--input   v-model="form.serialNum" border="none" placeholder="库存调拨单号"></u--input>
			</u-form-item>
			<u-form-item @click="arrivalDateShow=true" label="调拨日期" prop="repTransferDate" borderBottom ref="item1"  >
				<u--input    v-model="form.repTransferDate" border="none" placeholder="调拨日期"></u--input>
			<u-icon slot="right" name="arrow-right"></u-icon>
			</u-form-item>
			
			
			<u-form-item  label="负责人" prop="responsibleName" borderBottom ref="item1"  >
				<u--input  v-model="form.responsibleName" border="none" placeholder="负责人"></u--input>
			</u-form-item>
			<u-form-item @click="checkWhouse('1')" label="调出仓库" prop="outRepertory" borderBottom ref="item1"  >
				<u--input   v-model="form.outRepertory" border="none" placeholder="调出仓库"></u--input>
			<u-icon slot="right" name="arrow-right"></u-icon>
			</u-form-item>
			<u-form-item   label="调出仓库负责人" prop="outRepertoryName" borderBottom ref="item1"  >
				<u--input   v-model="form.outRepertoryName" border="none" placeholder="调出仓库负责人"></u--input>
			</u-form-item>
			
			<u-form-item @click="checkWhouse('2')" label="调入仓库" prop="inRepertory" borderBottom ref="item1"  >
				<u--input   v-model="form.inRepertory" border="none" placeholder="调入仓库"></u--input>
			<u-icon slot="right" name="arrow-right"></u-icon>
			</u-form-item>
			<u-form-item  label="调入仓库负责人" prop="inRepertoryName" borderBottom ref="item1"  >
				<u--input   v-model="form.inRepertoryName" border="none" placeholder="调入仓库负责人"></u--input>
			</u-form-item>
			<u-form-item @click="productListFn(form.outRepertory)" label="调拨产品" prop="syTransferProductTList" borderBottom ref="item1"  >
				 <u-icon slot="right" name="arrow-right"></u-icon>
			</u-form-item>
			 <view  style="padding-right: 5xp;margin-bottom: 5px;">
			 	<uni-table border stripe emptyText="暂无更多数据" >
			 		<!-- 表头行 -->
			 		<uni-tr>
			 			<uni-th align="center" width="70px">产品名称</uni-th>
			 			<uni-th align="center" width="60px">型号</uni-th>
			 			<uni-th align="center" width="50px">数量</uni-th>
			 			 <uni-th align="center" width="50px">仓库</uni-th>
			 		</uni-tr>
			 		<!-- 表格数据行 -->
			 		<uni-tr v-for="(item,index) in form.syTransferProductTList" :key="index">
			 			<uni-td align="center">{{item.productName}}</uni-td>
			 			<uni-td align="center">{{item.model}}</uni-td>
			 			<uni-td align="center">
			 				<template slot-scope="scope">
			 					<input @blur="isquantity(item,index)"  v-model="item.quantity" type="text"/>
			 				</template>
			 			</uni-td>
					<uni-td align="center">{{item.warehouseName}}</uni-td>
			 			 
			 		</uni-tr>
			 	</uni-table>
			 </view>
			 <u-form-item  @click="show=1" label="运输方式" prop="logisticsTypeName" borderBottom ref="item1">
			     <u--input :readonly="true" v-model="form.logisticsTypeName" border="none" placeholder="运输方式">
			     </u--input>
			     <u-icon slot="right" name="arrow-right"></u-icon>
			 </u-form-item>
			</u--form>
 
		<u-datetime-picker :closeOnClickOverlay="true" @close="arrivalDateShow=false"
			    :show="arrivalDateShow" v-model="dateNow" @confirm="arrivalDateConfirm"
			    @cancel="arrivalDateShow=false" mode="date"></u-datetime-picker>
		<u-picker :closeOnClickOverlay="true" @close="show=false" @cancel="show=false" @confirm="checkedFn"
				    :show="show==1" :columns="logisticsTypeOptions" keyName="dictLabel"></u-picker>
		<u-toast ref="uToast"></u-toast>
	</view>
</template>

<script>
	import {listTransfer,addTransfer,getTransfer,updateTransfer} from '@/api/tranfer.js'
	import {getDicts} from '@/api/dictionary/index.js'
	export default {
		data() {
			return {
				form:{
					outRepertory:'',
					outRepertoryNo:'',
					outRepertoryId:'',
					outRepertoryName:'',
					inRepertory:'',
					inRepertoryNo:'',
					inRepertoryId:'',
					inRepertoryName:'',
					logisticsType:'',
					syTransferProductTList:[]
				},//调拨单
				logisticform:{},
				arrivalDateShow:false,
				 show:false,
				 logisticsTypeOptionsDou:[],
				 logisticsTypeOptions:[]
			};
		},
		created() {
			this.form.serialNum=this.setOrderNo()
			this.form.responsibleName=this.$store.getters.name
		},
		onLoad(e) {
			this.getTranferInfo(e)
		  this.dateNow = this.getNowTime()
		  this.form.repTransferDate=this.dateNow
		  this.getShippingTypeOptions()
		},
		onBackPress(){
			this.getValueS()
		},
		methods:{
			//获取信息
			async getTranferInfo(e){
				let res=await getTransfer(e.id)
				 this.form=res.data
				this.form.logisticsTypeName = this.getDictValue(this.logisticsTypeOptionsDou, this
				    .form.logisticsType)
			},
			getValueS(item){
				console.log(item);
				if (Array.isArray(item)) {
				  this.form.syTransferProductTList = item
					this.form.syTransferProductTList.forEach(item=>{
						item.quantity=0
					})
				  
				} 
				if(item.type==1){
					 
					this.form.outRepertory=item.checkWarehouseName
					this.form.outRepertoryNo=item.warehouseNo
					this.form.outRepertoryId=item.responsibleUser
					this.form.outRepertoryName=item.responsibleUserName
					 
				}
				if(item.type==2){
					console.log(this.form,56);
					this.form.inRepertory=item.checkWarehouseName
					this.form.inRepertoryNo=item.warehouseNo
					this.form.inRepertoryId=item.responsibleUser
					this.form.inRepertoryName=item.responsibleUserName
				}
			},
			// 产品选择
			productListFn(val) {
				console.log(val,1212);
			    uni.navigateTo({
			        url: '/pages/dialog/product?warehouseName='+val
			    })
			},
			async btnok(){
				await updateTransfer(this.form)
				this.$refs.uToast.show({
					type:'success',
					message:"修改成功",
					complete(){
						uni.navigateBack({delta:1})
					}
				})
			},
			//跳转仓库
			checkWhouse(val){
				console.log(val,1212);
				uni.navigateTo({
					url:"/pages/dialog/warehouse/warehouse?type="+val
				})
			},
			arrivalDateConfirm(e) {
			    console.log(e);
			    this.form.repTransferDate = this.getTime(e.value)
			    this.arrivalDateShow = false
			},
			back(){
				uni.navigateBack({delta:1})
			},
			// 获取当前时间
			getNowTime() {
			    var date = new Date()
			    var month = date.getMonth() + 1;
			    var time = date.getFullYear() + "-" + month + "-" + date.getDate();
			    return time;
			},
			// 时间格式化
			getTime(val) {
			    var date = new Date(val);
			    var year = date.getFullYear(); //年 ,从 Date 对象以四位数字返回年份
			    var month = date.getMonth() + 1; //月 ,从 Date 对象返回月份 (0 ~ 11) ,date.getMonth()比实际月份少 1 个月
			    var day = date.getDate(); //日 ,从 Date 对象返回一个月中的某一天 (1 ~ 31)
			    //修改月份格式
			    if (month >= 1 && month <= 9) {
			        month = "0" + month;
			    }
			    //修改日期格式
			    if (day >= 0 && day <= 9) {
			        day = "0" + day;
			    }
			    var currentFormatDate = `${year}-${month}-${day}`;
			    return currentFormatDate
			},
			// 调拨单
			setOrderNo() {
			    var date = new Date();
			    var year = date.getFullYear(); //年 ,从 Date 对象以四位数字返回年份
			    var month = date.getMonth() + 1; //月 ,从 Date 对象返回月份 (0 ~ 11) ,date.getMonth()比实际月份少 1 个月
			    var day = date.getDate(); //日 ,从 Date 对象返回一个月中的某一天 (1 ~ 31)
			    //修改月份格式
			    if (month >= 1 && month <= 9) {
			        month = "0" + month;
			    }
			    //修改日期格式
			    if (day >= 0 && day <= 9) {
			        day = "0" + day;
			    }
			
			    let round = Math.floor(Math.random() * (999 - 100)) + 100;
			    var currentFormatDate = `${year}${month}${day}`;
			    return "DBD" + currentFormatDate + round;
			},
			// 获取运输方式
			getShippingTypeOptions() {
			    getDicts('biz_shipping_type').then(response => {
			        this.logisticsTypeOptionsDou = response.data
			        this.logisticsTypeOptions.push(response.data)
			        this.form.logisticsTypeName = this.getDictValue(this.logisticsTypeOptionsDou, this
			            .form.logisticsType)
			    })
			},
			checkedFn(e){
				 this.form.logisticsTypeName=e.value[0].dictLabel
				 this.form.logisticsType=e.value[0].dictValue
				 this.show=false
			},
			getDictValue(arr, item) {
			    for (var i = 0; i < arr.length; i++) {
			        if (item == arr[i].dictValue) {
			            return arr[i].dictLabel
			        }
			    }
			},
		}
	}
</script>

<style lang="scss">
.box{
	background-color: #fff;
	.form{
		padding-left: 10px;
	}
}
</style>
